public class test07 {
    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> hashset = new HashSet<>();
        ListNode cur = head;
        while(cur!=null){
            if(!hashset.add(cur)){
                return cur;
            }else{
                hashset.add(cur);
                cur = cur.next;

            }
        }
        return null;
    }
}
